/* this code is given by adiittya 0v0 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9+7;
// to find the power of number in case of high / large input values
int power(int i,int j,int p){
if(j==0){
return 1;
}
if(j==1){
return i;
}
long long ans=power(i,j/2,p);
ans=(ans*ans)%p;
if(j%2==1){
ans=(ans*i)%p;
}
return ans;
}
// pow exponentiation--> used to prevent the use of pow(a , n) method
double myPow(double x, int n) {
long long nn=n;
double ans=1.0;
if(nn<0)
nn=-1*nn;
while(nn)
{
if(nn%2)
{
ans=ans*x;
nn=nn-1;
}
else
{
x=x*x;
nn=nn/2;
}
}
if(n<0)
return (double)(1.0)/(double)(ans);
else
return ans;
}
// Prime func. in sqrt(n) - time
bool isprime(int n)
{
// Corner case
if (n <= 1)
return false;
// Check from 2 to square root of n
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------------------------------------
bool fun(int n, int m)
{
if(n%3!=0)
return false;
if(n/3==m || 2*(n/3)==m)
return true;
else
{
if(fun(n/3 , m))
return true;
if(fun(2*(n/3) , m))
return true;
}
return false;
}
// solve func. to write any program.
void solve()
{
ll n, m;
cin>>n>>m;
if(n==m)
{
cout<<"YES"<<endl;
return;
}
if(n%3!=0 || m>n)
{
cout<<"NO"<<endl;
return;
}
if(fun(n, m))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------------------------------------
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll a;
cin>>a;
while(a--)
{
solve();
}
}
// 11
// 6 4
// YES
// 9 4
// YES
// 4 2
// NO
// 18 27
// NO
// 27 4
// YES
// 27 2
// YES
// 27 10
// YES
// 1 1
// NO
// 3 1
// YES
// 5 1
// NO
// 746001 2984004
// NO
// 11
// 6 4
// YES
// 9 4
// YES
// 4 2
// NO
// 18 27
// NO
// 27 4
// YES
// 27 2
// YES
// 27 10
// NO
// 1 1
// YES
// 3 1
// YES
// 5 1
// NO
// 746001 2984004
// NO
// YES
// 9 4
// YES
// 4 2
// NO
// 18 27
// NO
// 27 4
// YES
// 27 2
// YES
// 27 10
// NO
// 1 1
// YES
// 3 1
// YES
// 5 1
// NO
// 746001 2984004
// NO
1607A - Linear Keyboard | EQUALCOIN Equal Coins |
XOREQN Xor Equation | MAKEPAL Weird Palindrome Making |
HILLSEQ Hill Sequence | MAXBRIDGE Maximise the bridges |
WLDRPL Wildcard Replacement | 1221. Split a String in Balanced Strings |
1002. Find Common Characters | 1602A - Two Subsequences |
1555A - PizzaForces | 1607B - Odd Grasshopper |
1084A - The Fair Nut and Elevator | 1440B - Sum of Medians |
1032A - Kitchen Utensils | 1501B - Napoleon Cake |
1584B - Coloring Rectangles | 1562B - Scenes From a Memory |
1521A - Nastia and Nearly Good Numbers | 208. Implement Trie |
1605B - Reverse Sort | 1607C - Minimum Extraction |
1604B - XOR Specia-LIS-t | 1606B - Update Files |
1598B - Groups | 1602B - Divine Array |
1594B - Special Numbers | 1614A - Divan and a Store |
2085. Count Common Words With One Occurrence | 2089. Find Target Indices After Sorting Array |